import {
    messageBoxAlter
} from "@/func/alter"


import {
    IQueryStats,
    IReadKlineData,
    IReadFieldData,
    IReadUdList,
} from "@/api/factor"

import {
    IGetFileFieldList
} from "@/api/fileMgr"

export async function getStats (workspace:any, facName:any){
    let facFilePath = workspace + "/" + facName

    const result = await IQueryStats(facFilePath)
    if (result.success){
        return result.data
    }
    else{
        messageBoxAlter("getStats", result.msg)
        return null
    }
}

export async function getKlineData (workspace:any, facName:any, underlying:string, sDate?:string, eDate?:string, fileName:string="factorDetail.csv"){
    let facFilePath = workspace + "/" + facName + "/" + fileName

    const result = await IReadKlineData(facFilePath, underlying, sDate, eDate)
    if (result.success){
        return result.data
    }
    else{
        messageBoxAlter("getKlineData", result.msg)
        return null
    }
}

export async function getFactorFieldList(workspace:any, facName:any, fileName:string="factorDetail.csv") {
    let facFilePath = workspace + "/" + facName + "/" + fileName

    const result = await IGetFileFieldList(facFilePath)
    if (result.success){
        return result.data
    }
    else{
        messageBoxAlter("getFactorFieldList", result.msg)
        return null
    }
}

export async function getFieldData(workspace:any, facName:any, underlying:string, field:string[], sDate?:string, eDate?:string, fileName:string="factorDetail.csv") {
    let facFilePath = workspace + "/" + facName + "/" + fileName

    const result = await IReadFieldData(facFilePath, underlying, field, sDate, eDate)
    if (result.success){
        return result.data
    }
    else{
        messageBoxAlter("getFieldData", result.msg)
        return null
    }
}

export async function getUdList(workspace:any, facName:any, fileName:string="factorDetail.csv") {
    let facFilePath = workspace + "/" + facName + "/" + fileName

    const result = await IReadUdList(facFilePath)
    if (result.success){
        return result.data
    }
    else{
        messageBoxAlter("IReadUdList", result.msg)
        return null
    }
}


